(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.dataInquiry.viewController', viewController);
	viewController.$inject = [ '$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'dataInquiryService' ];
	function viewController($scope, Constants, layoutConfig, validatorConfig, gridService, authService, dataInquiryService) {
		var ctrl = this, dataInquiryInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;

		ctrl.dataInquiry = {};
		ctrl.dataInquiry.paramList = ctrl.dataInquiry.paramList || [];
		
		ctrl.serviceCodeOptions = {};
		ctrl.dinqFilebuilderIdOptions = {};
		ctrl.parmTypeOptions = {};
		
		ctrl.init = function() {
			var params = {
				dinquiryId : dataInquiryInfo.dinquiryId
			};
			ctrl.innerGridOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.params.tableConfigs.table);
			ctrl.innerGridOptions.data = 'vm.dataInquiry.paramList';
			ctrl.innerGridOptions.enableRowHeaderSelection = false;
			return authService.view(params).then(function(response) {
				ctrl.dataInquiry = response.data || dataInquiryInfo;
				ctrl.dataInquiry.paramList = ctrl.dataInquiry.paramList || [];
				angular.extend(ctrl.serviceCodeOptions,  response.data.services);
				angular.extend(ctrl.dinqFilebuilderIdOptions,  response.data.dataInquiryBuilders);
				angular.extend(ctrl.parmTypeOptions,  response.data.dataTypes);
			}, angular.noop);
		};
		
		ctrl.initAccessTypeListOption = function(models, option){
			if(ctrl.dataInquiry){
				angular.forEach(ctrl.dataInquiry.inquiryAccess, function(obj){
					var item = {
							"label" : obj.dinqAccessType + " - " + obj.dinqAccessDesc,
							"value" : obj.dinqAccessType
					};
					option.data.push(item);
				});
			}
		};
		
	}
})(angular);